package com.heyqing.medium.day2;

/**
 * ClassName:Reverse
 * Package:com.heyqing.medium.day2
 * Description:
 *
 * @Date:2024/10/3
 * @Author:Heyqing
 */
public class Reverse {
    public int reverse(int x) {
        int flag = 1;
        long xL = x;
        if (x < 0) {
            flag = -1;
            xL *= flag;
        }
        StringBuilder sb = new StringBuilder(String.valueOf(xL));
        String reverseX = sb.reverse().toString();
        if (Long.parseLong(reverseX) * flag > Integer.MAX_VALUE || Long.parseLong(reverseX) * flag < Integer.MIN_VALUE)
            return 0;
        return Integer.parseInt(reverseX) * flag;
    }
}
